package com.xyg.rbac.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Transient;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.util.Assert;

import com.xyg.common.model.DataEntity;



public class User extends DataEntity<User, Long> implements UserDetails {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -5920722314773933067L;

	/**密码*/
	private String password;
	
	/**用户名*/
	private String username;
	
	/**帐号是否超出有效期*/
	private boolean accountNonExpired = false;
	
	/**帐号是否锁定*/
	private boolean accountNonLocked = false;
	
	/**密码是否超出有效期*/
	private boolean credentialsNonExpired = false;
	
	/**是否可用*/
	private boolean enabled = false;
	
	/**角色*/
	private Set<Role> roles = new HashSet<>();
	
	@Transient
	/**权限*/
	private Set<Authority> authorities = new HashSet<>();

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public boolean isAccountNonExpired() {
		return accountNonExpired;
	}

	public void setAccountNonExpired(boolean accountNonExpired) {
		this.accountNonExpired = accountNonExpired;
	}

	public boolean isAccountNonLocked() {
		return accountNonLocked;
	}

	public void setAccountNonLocked(boolean accountNonLocked) {
		this.accountNonLocked = accountNonLocked;
	}

	public boolean isCredentialsNonExpired() {
		return credentialsNonExpired;
	}

	public void setCredentialsNonExpired(boolean credentialsNonExpired) {
		this.credentialsNonExpired = credentialsNonExpired;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public Set<Authority> getAuthorities() {
		Assert.notEmpty(roles);
		for (Role role : roles) {
			authorities.add(role.getAuthority());
		}
		return authorities;
	}


	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
	
	
	

}
